package com.egg.basic.fegin.fallback;

import com.egg.basic.enums.sms.SmsTypeEnum;
import com.egg.basic.fegin.BasicSmsFeignClient;
import com.egg.common.core.enums.ResponseCode;
import com.egg.common.core.model.response.ResponseData;
import feign.hystrix.FallbackFactory;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestParam;


/**
 * feignClient降级
 *
 * @author east
 */
@Slf4j
@Configuration
public class BasicSmsFeignClientFallback implements FallbackFactory<BasicSmsFeignClient> {


    @Override
    public BasicSmsFeignClient create(Throwable cause) {
        return new BasicSmsFeignClient() {

            @Override
            public ResponseData<String> sendSms(
                    @ApiParam(value = "手机号码", required = true) @RequestParam(value = "phone") String phone
                    , @ApiParam(value = "业务类型", required = true) @RequestParam(value = "smsType") SmsTypeEnum smsType
            ) {
                ResponseData res = new ResponseData<>();
                res.setMsg(ResponseCode.FALLBACK_ERROR.getMessage());
                res.setCode(ResponseCode.FALLBACK_ERROR.getCode());
                return res;
            }

            @Override
            public ResponseData<Boolean> verifySms(
                    @ApiParam(value = "手机号码", required = true) @RequestParam(value = "phone") String phone
                    , @ApiParam(value = "业务类型", required = true) @RequestParam(value = "smsType") SmsTypeEnum smsType
                    , @ApiParam(value = "验证码", required = true) @RequestParam(value = "verifyCode") String verifyCode
            ) {
                ResponseData res = new ResponseData<>();
                res.setMsg(ResponseCode.FALLBACK_ERROR.getMessage());
                res.setCode(ResponseCode.FALLBACK_ERROR.getCode());
                return res;
            }

        };
    }


}